package it.aekidna.cleverplatypus.workflow.template
{
	import flash.utils.getQualifiedClassName;
	
	import it.aekidna.cleverplatypus.workflow.AbstractWorkflowTask;
	
	import mx.logging.ILogger;
	import mx.logging.Log;
	import mx.logging.LogEventLevel;
	
	import org.as3commons.reflect.Method;
	import org.as3commons.reflect.Type;

	public class LogTask extends AbstractWorkflowTask
	{

		private static const LOGGER : ILogger = 
			Log.getLogger( getQualifiedClassName( LogTask ).replace(/:+/g, "." ) );
		
		public var message : String = "[REPLACE ME]";
		public var parameters : Array = [];
		
		[Inspectable(defaultValue="debug", enumeration="debug,info,warn,error,fatal")]
		public var level : String = "debug";
		
		private var _levels : Object =
			{
				debug : LogEventLevel.DEBUG,
				info : LogEventLevel.INFO,
				warn : LogEventLevel.WARN,
				error : LogEventLevel.ERROR,
				fatal : LogEventLevel.FATAL
			};
		
		override public function begin() : void
		{
			var args : Array = [ _levels[ level ], message ];
			args = args.concat( parameters );
			
			var type : Type = Type.forInstance( LOGGER );
			var method : Method = type.getMethod( "log" );
			method.invoke( LOGGER, args );
			complete();
		}		
	}
}